﻿using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using FeatureManagement.JsonConverters;
using FeatureManagement.Localization;
using Xms.Abp.Modularity;
using Xms.Abp.AspNetCore.Mvc;

namespace FeatureManagement;

[DependsOn(
    typeof(FeatureManagementApplicationContractsModule),
    typeof(XmsAbpAspNetCoreMvcModule))]
public class FeatureManagementHttpApiModule : XmsModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure<IMvcBuilder>(mvcBuilder =>
        {
            mvcBuilder.AddApplicationPartIfNotExists(typeof(FeatureManagementHttpApiModule).Assembly);
        });
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpLocalizationOptions>(options =>
        {
            options.Resources
                .Get<FeatureManagementResource>()
                .AddBaseTypes(typeof(AbpUiResource));
        });

        Configure<JsonOptions>(options =>
        {
            options.JsonSerializerOptions.Converters.AddIfNotContains(new StringValueTypeJsonConverter());
        });
    }
}
